/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.tendon.convert.json;

import com.tencent.tendon.convert.util.*;

/**
 *
 * @author nbzhang
 */
public final class JsonPool {

	private static final ObjectPool<AnyArray> anyArrayPool = new ObjectPool<AnyArray>(Math.max(Integer.parseInt(System.getProperty("PoolMaxSize." + AnyArray.class.getSimpleName(), "2")), 16), new Creator<AnyArray>() {

		public final AnyArray create(Object... params) {
			return new AnyArray();
		}
	});

	protected static final ObjectPool<CharArray> charArrayPool = new ObjectPool<CharArray>(Math.max(Integer.parseInt(System.getProperty("PoolMaxSize." + CharArray.class.getSimpleName(), "2")), 16), new Creator<CharArray>() {

		public final CharArray create(Object... params) {
			return new CharArray();
		}
	});

	private static final ObjectPool<JsonDefaultReader> defaultReaderPool = new ObjectPool(Integer.parseInt(System.getProperty("PoolMaxSize." + JsonDefaultReader.class.getSimpleName(), "2")), new Creator<JsonDefaultReader>() {

		public final JsonDefaultReader create(Object... params) {
			return new JsonDefaultReader();
		}
	});

	private static final ObjectPool<JsonDefaultWriter> defaultWriterPool = new ObjectPool(Integer.parseInt(System.getProperty("PoolMaxSize." + JsonDefaultReader.class.getSimpleName(), "2")), new Creator<JsonDefaultWriter>() {

		public final JsonDefaultWriter create(Object... params) {
			return new JsonDefaultWriter();
		}
	});

	private JsonPool() {
	}

	public static AnyArray pollAnyArray() {
		return anyArrayPool.poll();
	}

	public static void offer(AnyArray e) {
		anyArrayPool.offer(e);
	}

	public static CharArray pollCharArray() {
		return charArrayPool.poll();
	}

	public static void offer(CharArray e) {
		charArrayPool.offer(e);
	}

	public static JsonDefaultReader pollJsonDefaultReader() {
		return defaultReaderPool.poll();
	}

	public static void offer(JsonDefaultReader e) {
		defaultReaderPool.offer(e);
	}

	public static JsonDefaultWriter pollJsonDefaultWriter() {
		return defaultWriterPool.poll();
	}

	public static void offer(JsonDefaultWriter e) {
		defaultWriterPool.offer(e);
	}
}
